package org.stone.project.commonPojo.customEnum;

import cn.hutool.core.util.ObjectUtil;

/**
 * 模板枚举
 */
public enum  TemplateEnum {
    ;

    TemplateEnum(String descriptionStr, int code) {
        this.descriptionStr = descriptionStr;
        this.code = code;
    }

    /**
     * 描述
     */
    public String descriptionStr;

    /**
     * 状态值
     */
    public int code;

    /**
     * 通过状态值获取枚举
     * @param code
     * @return
     */
    public static TemplateEnum getInstanceByCode(Integer code){
        if (ObjectUtil.isNull(code))
            return null;
        for (TemplateEnum value : TemplateEnum.values()) {
            if (value.code == code)
                return value;
        }
        return null;
    }

    /**
     * 通过描述获取枚举
     * @param descriptionStr
     * @return
     */
    public static TemplateEnum getInstanceByDesStr(String descriptionStr){
        if (ObjectUtil.isNull(descriptionStr))
            return null;
        for (TemplateEnum value : TemplateEnum.values()) {
            if (value.descriptionStr == descriptionStr)
                return value;
        }
        return null;
    }
}
